import React, { Component } from 'react';
import { connect } from 'dva';
import { Form, Button, Input } from 'antd';
import ManageList from '@/components/ManageList';
import { init, doCAIdentify, downEportIkeySetup } from './Websocket';
import { allDispatchType } from './utils';
import prompt from '@/components/Prompt';

@ManageList
@connect(({ iccard }) => ({
  iccard,
}))
@Form.create()
export default class Cookie extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    // this.props.form.validateFields();
    this.props.onRef(this);
    init();
  }
  handleSubmit = e => {
    e && e.preventDefault();
    const { dispatch, random, id } = this.props;
    this.props.form.validateFields((err, values) => {
      if (!err) {
        console.log('values===== ', values);
        const result = doCAIdentify({
          callback: res => {
            console.log('获取到IC卡信息=========', res);

            if (res.Error && res.Error.length > 0) {
              prompt({ content: res.Error, type: 'warn' });
            } else {
              let ary = new Array();
              let user = res.Data[1];
              ary = user.split('||');
              console.log('res.Data[1]', res.Data[0]);
              console.log('ary=====', ary);

              dispatch({
                type: allDispatchType.cookiesRefresh,
                payload: {
                  certNo: ary[0],
                  icCard: ary[5],
                  icCardId: id,
                  random: random,
                  signData: res.Data[0],
                  password: values.password,
                  swCardF: '1',
                  logoutFlag: '1',
                },
                callback: data => {
                  console.log('data', data);
                },
              });
            }
          },
        });
      }
    });
  };
  //下载插件：
  downEportIkeySetup = e => {
    e && e.preventDefault();
    downEportIkeySetup();
  };

  render() {
    const {
      form: { getFieldDecorator },
      random,
    } = this.props;
    const {} = this.state;

    return (
      <div>
        <Form>
          <Form.Item></Form.Item>
          <Form.Item label="IC卡密码">
            {getFieldDecorator('password', {
              rules: [{ required: true, message: '请输入IC卡密码' }],
            })(<Input type="password" placeholder="请输入IC卡密码" />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('icCard', {})(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('certNo', {})(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('signData', {})(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('random', { initialValue: random })(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('serverDate', { initialValue: '20191017100304=' })(
              <Input placeholder="" />
            )}
          </Form.Item>

          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('userPin', { initialValue: 'userPin' })(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('lt', {
              initialValue: 'LT-36701-7i2ixYVatzthhVBj0HUc-app.singlewindow.cn',
            })(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('execution', {
              initialValue:
                'd2ddc93a-e0f0-4644-acc4-0b64409f21df_ZXlKaGJHY2lPaUpJVXpVeE1pSjkuWkhCTmQwVlVSekpJVkM5Qk5GUlJNVmMyUWpWVlpqaDZkMjFVUVVkMFIzQmxVRTFxWTA1UUwwbHplUzlVTUU5dk5sRldSMDF1T1M5TGJrVkxiWFZEYkVsMWFXcDZhakUxUm1GbFIwZHhielJVY1RWM2VFdFFlak14WTB0MldrWnBVM04xV2tsTVIwVklhVk5vVHpWc1NuQlZUWEJKUkVaMlEwbENiRmh0Vkc5bFpuUm1RM1JGT1hScE0ycE1NbVZZZDNSTlpVUkNjR1JVU0RKM2NtWTBMMWx2V0dOcGRtVm9hSGxQYnk4MVJHdFdiRXhzYm1VemFsQXZRM1JSTWpoMVYzaEpiM280U0V4SU5HMTJWbUZvU2tZeVUyVkpaemRCYjFSeVkwcHdOVUpKU1ZCclZHaFBZMEpwTmxSNFVVcHVWMFI1VkZOb05FbGlkM0phV2pWSVVrTjZlbEJNWVVSR1dHUTRUbGh1UVdweWMzSmtVbEptVVVkNmFFMVplSEZzTkcxT01XY3hlWEJKWnpkRUwwVjZRblo2VEVZeVNuUmhlakpJVTFFMU5YQnpNamxwY2tZMU1rbEhWM2RpTkdkQk9HcE9VMlk1UW1OaU4wMXZURWxEZW5oRlpsRn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ZXT1RCemNXcHNVVEpoVERrdlRtZFVLMWxaTTBOV09ISkhXbWxGTVdWSk5rWlVUVE5STkRaQmJDOTZiVTlyV2xGVVVGcEdjazVDVjJGVE0yZHVRMlZqYzFGMVJFMDRVMFp2ZWtoM1BUMC5aZnBjMTBVd05raTMtVG9uX3FWSWtvTXY1ZWlxanVrY1ZWdkIxQmo1aWgwTHVueXVMeHkxVWw2UXE2U1MtTDlFWEgxcG45RzdxM1FGcGpWaXFfWG45Zw==',
            })(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('swLoginFlag', { initialValue: 'swCard' })(<Input />)}
          </Form.Item>
          <Form.Item style={{ display: 'none' }}>
            {getFieldDecorator('lpid', { initialValue: 'P2' })(<Input />)}
          </Form.Item>
        </Form>

        <p className="login_fgt">
          请您按照以下步骤进行：
          <br />
          1、请先插入IC卡。
          <br />
          2、在输入框中输入IC卡密码。
        </p>
        <div class="login_dlfs">
          <div class="login_dlfs_05" style={{ textAlign: 'right' }} id="download_widget">
            <a
              onClick={e => this.downEportIkeySetup(e)}
              href="javascript:void(0)"
              id="downocx"
              target="_blank"
            >
              客户端控件下载
            </a>
          </div>
        </div>
      </div>
    );
  }
}
